package com.tanzeer.deliverytracker.adapter;

import java.util.List;

import com.tanzeer.deliverytracker.R;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SpinnerItemAdapter extends ArrayAdapter<String> {

	public Context context;

	public SpinnerItemAdapter(Context context, int textViewResourceId,
			List<String> items) {
		super(context, textViewResourceId, items);
		Log.e("msg", "" + items.size());
		this.context = context;

	}

	private class ViewHolder {

		TextView name;
		ImageView icons;

	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		return GetCustomView(position, convertView, parent);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return GetCustomView(position, convertView, parent);

	}

	private View GetCustomView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		LayoutInflater mInflater = (LayoutInflater) context
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.spinner_row_view_custom,
					null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.textViewop);
			holder.icons = (ImageView) convertView
					.findViewById(R.id.imageView1);
			convertView.setTag(holder);

		} else
			holder = (ViewHolder) convertView.getTag();
		// Log.v("msg","hello");
		String opName = getItem(position);

		holder.name.setText(opName);
		// setting icon
		if (opName.equals("Incoming")) {
			holder.icons.setBackgroundResource(R.drawable.incoming);
		} else if (opName.equals("Outgoing")) {
			holder.icons.setBackgroundResource(R.drawable.outgoing);
		} else if (opName.equals("Favorite")) {
			holder.icons.setBackgroundResource(R.drawable.favorite);
		} else if (opName.equals("Movie")) {
			holder.icons.setBackgroundResource(R.drawable.film_reel);
		} else if (opName.equals("Gift")) {
			holder.icons.setBackgroundResource(R.drawable.present);
		} else if (opName.equals("Heart")) {
			holder.icons.setBackgroundResource(R.drawable.heart);
		} else if (opName.equals("Business")) {
			holder.icons.setBackgroundResource(R.drawable.business);
		} else if (opName.equals("Important")) {
			holder.icons.setBackgroundResource(R.drawable.important);
		} else if (opName.equals("Camera")) {
			holder.icons.setBackgroundResource(R.drawable.camera_unmount2);
		} else if (opName.equals("Clothes")) {
			holder.icons.setBackgroundResource(R.drawable.clothes);
		} else if (opName.equals("Computer")) {
			holder.icons.setBackgroundResource(R.drawable.mycomputer);
		} else if (opName.equals("Games")) {
			holder.icons.setBackgroundResource(R.drawable.gaming_pad);
		} else if (opName.equals("Food Dishes")) {
			holder.icons.setBackgroundResource(R.drawable.fooddishes);
		} else if (opName.equals("Light")) {
			holder.icons.setBackgroundResource(R.drawable.light);
		} else if (opName.equals("Music")) {
			holder.icons.setBackgroundResource(R.drawable.kbemusedsrv);
		} else if (opName.equals("Office Materials")) {
			holder.icons.setBackgroundResource(R.drawable.office);
		} else if (opName.equals("Paint")) {
			holder.icons.setBackgroundResource(R.drawable.kolourpaint);
		} else if (opName.equals("Medicine")) {
			holder.icons.setBackgroundResource(R.drawable.pill);
		} else if (opName.equals("Flowers")) {
			holder.icons.setBackgroundResource(R.drawable.flowers);
		} else if (opName.equals("Sports")) {
			holder.icons.setBackgroundResource(R.drawable.sports);
		} else if (opName.equals("Tools")) {
			holder.icons.setBackgroundResource(R.drawable.tool2);
		} else if (opName.equals("None")) {
			holder.icons.setBackgroundResource(R.drawable.white);
		}
		return convertView;
	}

	private void seticon(String str) {
		if (str.equals("Incoming ")) {

		}

	}
}
